/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.just.dusin.ooii.component.kj;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.dusin.webcoal.exception.OOIIException;
import org.just.dusin.ooii.component.Source;

/**
 *
 * @author Admin
 */
public class CollectorPollSource extends Source{
    private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(CollectorPollSource.class.getName());
    private List<Collector> collectorList= new ArrayList<Collector>();
    private int inteval = 300; //轮询延时
    private String comPortId="com1";

    public int getInteval() {
        return inteval;
    }

    public void setInteval(int inteval) {
        this.inteval = inteval;
    }
    
    
    
    public List<Collector> getCollectorList() {
        return collectorList;
    }

    public void setCollectorList(List<Collector> collectorList) {
        this.collectorList = collectorList;
    }   
    
    @Override
    public void run() {
        while(!stop){
            for(Collector c: collectorList){
                Map<String,Object> map = c.retrieve();
                double currentTotal = (Double) map.get("currentTotal");
                double flowSpeed = (Double) map.get("flowSpeed");
                double beltSpeed = (Double) map.get("beltSpeed");
                byte shellOpen = (Byte) map.get("shellOpen");
                int type = (Integer) map.get("type");
                int no = (Integer) map.get("no");
                String msg= DataPackage.packYBSJ(no,currentTotal,flowSpeed,beltSpeed,shellOpen,type);
                try {
                    sink.process(msg);
                    Thread.sleep(no);
                } catch (InterruptedException ex) {
                    logger.error(ex.getMessage());
                } catch (OOIIException ex) {
                    logger.error(ex.getMessage());                    
                }
            }
        }
    }

    String getPortId() {
        return this.comPortId;
    }

    public void setComPortId(String comPortId) {
        this.comPortId = comPortId;
    }
    
    
    
}
